#!/usr/bin/python

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


import os
import dbus

##
## Class definitions ---------------------------------------------------------------------------------------

## TrayNotifyMsgr - Used to create objects to send messages to the system tray icon
class TrayNotifyMsgr:
	## init - Creates a handle to the D-BUD Sytstem bus and gives it an interface identifier
	def __init__(self):
		self.bus = dbus.SystemBus()
		self.interface = 'org.PyTrayNotify.Interface'

	## send_signal - Signals the D-BUS listener attached to the tray icon.
	## *args - 1. message_string, a string consisting of the message to be displayed
	def send_signal(self, signal_name, *args):
	    message = dbus.lowlevel.SignalMessage('/', self.interface, signal_name)
	    message.append(*args)
	    self.bus.send_message(message)

## Main program if run stand-alone   
if __name__ == '__main__': 
	## Create a messenger object
	msgr = TrayNotifyMsgr()
	priority = 2
	title = "pytraynotify test"
	msg = "This is a test"
	## Send a test message to the Tray Icon
	msgr.send_signal('traynotify_msg',priority,title,msg)

